﻿/*****************************************
 * 
 *  copyright (c) by ylshen
 * 
 *  author : ylshen (syl.lucky@gmail.com)
 *  
 **************************************** */
using System;
using System.Collections.Generic;
using System.Text;

namespace JYStockAnalyser.Model
{
    /// <summary>
    /// 增长率统计项生成器
    /// </summary>
    public class GrowthStatItemBuilder
    {
        public static List<GrowthStatItem> Builditems(List<GuideLine> lines)
        {
            List<GrowthStatItem> items = new List<GrowthStatItem>();

            GuideLine firstLine = lines[0];          
            for (int i = 0; i < lines.Count; i++)
            {
                GuideLine line = lines[i];
                GrowthStatItem item = new GrowthStatItem();
                item.Period = line.GetTimeSimpleString();
                item.GuideLineValue = line.ToValueString();
                if (i == 0)
                {
                    item.GrowthRate = "－";
                    item.CompoundGrowthRate = "－";
                }
                else
                {
                    decimal perValue = lines[i - 1].Value;
                    item.GrowthRate = FinancialCalculator.GetGrowthRateString(perValue, line.Value);
                    item.CompoundGrowthRate = FinancialCalculator.GetCompoundGrowthRateString(firstLine.Value, line.Value, i);
                }
                items.Add(item);
            }
            return items;
        }
    }
}
